package com.example.zhxy.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.zhxy.pojo.Teacher;
import com.example.zhxy.service.TeacherService;
import com.example.zhxy.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
/**
 * CJ
 */
@Api(tags = "教师管理控制层")
@Slf4j
@RestController
@RequestMapping("/sms/teacherController")
public class TeacherController {
    @Autowired
    private TeacherService teacherService;
    @ApiOperation("分页")
    @GetMapping("/getTeachers/{pageNo}/{pageSize}")
    public Result page(
            @PathVariable Integer pageNo,
            @PathVariable Integer pageSize,
            Teacher teacher){
        Page page=new Page(pageNo,pageSize);
        IPage page1=teacherService.IPage(page,teacher);
        return Result.ok(page1);
    }
    @ApiOperation("新增和更新")
    @PostMapping("/saveOrUpdateTeacher")
    public Result saveOrUpdateTeacher(@RequestBody Teacher teacher){
        boolean b = teacherService.saveOrUpdate(teacher);
        if(b){
            return Result.ok();
        }else return Result.fail().message("新增或修改失败");
    }@ApiOperation("批量删除")
    @DeleteMapping("/deleteTeacher")
    public Result remove(@RequestBody  List<Integer> list){
        teacherService.removeByIds(list);
        return Result.ok();
    }
}
